#include "ChatLimitPlugin.h"
#include "Log.h"
#include "Expand/PluginsManager.h"
#include "Expand/EventManager.h"

#include "Game/IInventory.hpp"
#include "Managers/GameManager.h"

#include "Components/ComponentInventory.h"
#include "Network/Client.h"
#include "Player/PlayerData.h"

#include "GameSingleton.h"
#include "Network/PackageManager.h"
#include "Network/Packages/MessagePackage.h"
#include "Network/ServerRoot.h"

#include "SubsystemChatLimit.h"

namespace ChatLimit
{
    ChatLimitPlugin::ChatLimitPlugin()
    {
        m_chatLimit = GameSingleton::gameManager->registerSubsystem<SubsystemChatLimit>();

        m_playerEvent = new PlayerEvent(m_chatLimit);
        GameSingleton::eventManager->addEvent<IPlayerEvent>(m_playerEvent);

    }

    const std::string &ChatLimitPlugin::getPluginName()
    {
        static const std::string pluginName = "发言限制插件";
        return pluginName;
    }

    const std::string &ChatLimitPlugin::getIntroduce()
    {
        static const std::string introduce = "\n/chat clear - 清理掉消息次数记录";
        return introduce;
    }

    uint32_t ChatLimitPlugin::getUseAuthLevel()
    {
        return 100;
    }

    AuthDisplayType ChatLimitPlugin::getDisplayType()
    {
        return AuthDisplayType::Authority;
    }

    void ChatLimitPlugin::processCmd(ChatObj &chatObj, std::vector<std::string> &cmdDataVec)
    {
        if(cmdDataVec.size() >= 2)
        {
            if(cmdDataVec[1] == "clear")
            {
                m_chatLimit->clearMessageCount();
                chatObj.sendMessage("test", "成功清理掉消息次数记录");
            }
        }
    }

    void ChatLimitPlugin::load() {}

    void ChatLimitPlugin::getCmds(std::vector<std::string> &cmdVec)
    {
        cmdVec.push_back("/chat");
    }

} // namespace PocketSurvival


using namespace PocketSurvival;

extern "C" void initialize()
{
    GameSingleton::pluginsManager->registerPlugin<ChatLimit::ChatLimitPlugin>();
    Log::Info("成功加载 ChatLimitPlugin 插件");
}